/* eslint-disable */
import axios from 'axios';
import store from './store';
import { constants } from './common/js/constants.js'
// import router from './router';

//创建一个axios实例
const instance = axios.create({
  baseURL: 'http://192.168.3.12:6066/api/',
  timeout: 1000,
  headers: {'Content-Type': 'application/json;charset=UTF-8'}
});

//request拦截器
instance.interceptors.request.use(
    config => {
    	// 每次请求检查localStorage中是否有token, 有就配置到请求头中去
        let token = window.localStorage.getItem(constants.STORAGE_TOKEN_KEY);
        if(token){
            config.headers.Authorization = `token ${token}`;
        }
        return config;
    },
    err => {
        return Promise.reject(err);
    }
);

export default instance;